<template>
  <div>
    <div class="mask" v-show="maskShow" @click="maskShow = false"></div>
    <div
      class="info-item"
      v-for="(item, index) in dataList"
      :key="index"
      @click="handleLinkId(item)"
    >
      <img class="pic" :class="type == 3 ? 'rad' : ''" :src="item.headUrl" alt="" />
      <div class="info-box">
        <div class="info">
          <div class="name-time">
            {{ type == 3 ? item.twitterName?item.twitterName:item.entityName  : item.entityName }}
            <div class="btn-box">
              <div
              @click.stop="_GetUserGroups(item.entityId || null)"
              v-if="item.attention == 2"
            >
              <el-popover
                ref="popover"
                class="popver"
                placement="left"
                width="190"
                trigger="click"
              >
                <div
                  class="follow-tab"
                  v-loading="loading"
                  element-loading-spinner="el-icon-loading"
                  element-loading-background="rgba(0, 0, 0, 0.8)"
                >
                  <p class="tit">设置分组</p>
                  <p
                    class="tab-item"
                    v-for="(items, indexs) in followLab"
                    :key="indexs"
                    @click.capture="changeFollow(items)"
                  >
                    <span
                      class="check"
                      :class="items == selectGroups ? 'active' : ''"
                    ></span>
                    {{ items }}
                  </p>
                  <p class="tab-item">
                    <span class="check"></span>
                    <input class="label-msg" type="text" v-model="labelMsg" />
                  </p>
                  <p class="tab-item" @click="addLab(followLab)">
                    <i class="el-icon-plus"></i>
                    <span class="add">新建分组</span>
                  </p>
                  <button class="saveLab" @click="attentionRecord(item, index)">
                    确定
                  </button>
                </div>
                <span class="follow no" slot="reference"
                  ><i class="el-icon-plus"></i>关注</span
                >
                
              </el-popover>
            </div>
            <span
              v-loading="item.loading"
              v-else
              class="follow"
              @click.stop="cancelRecord(item, index)"
              >已关注</span
            >
            <span class="follow no" slot="reference" v-if="isDel"
             @click.stop="removeRecord(item, index)"
                  ><i class="el-icon-delete"></i>删除</span
                >
            </div>
          </div>
          <p class="label" v-if="type != 3">
            <span v-for="(items, indexs) in item.labelTypes" :key="indexs">{{
              items
            }}</span>
          </p>
          <p class="info-tit ellipsis2">
            {{ item.mentions ? item.mentions : item.abstractType }}
          </p>
        </div>
        <p class="all" v-if="type == 3">
          <span>
            <i class="iconf icontwitter"></i>
            推文总数：{{ item.twitterAmout }}
          </span>
          <span>
            <i class="iconf iconwujiaoxing"></i>
            关注：{{ item.twitterAttention }}
          </span>
          <span>
            <i class="iconf iconxin"></i>
            粉丝：{{ item.twitterFans }}
          </span>
        </p>
      </div>
    </div>
  </div>
</template>

<script>
import {
  GetUserGroups,
  CancelPersonRecord,
  AttentionPersonRecord,
} from "@/api/personal";
import {
  AttentionOrganizationRecord,
  CancelOrganizationRecord,
} from "@/api/organization";
import { AttentionTwitterRecord, CancelTwitterRecord } from "@/api/twitter";
import { AttentionThemeRecord, CancelThemeRecord } from "@/api/theme";
import { tipSuc, tipErr } from "@/utils/index";
export default {
  name: "infoItem",
  props: {
    dataList: {
      type: Array,
      default: function() {
        return [];
      },
    },
    type: {
      type: Number,
      default: 1,
    },
    isDel:{
      type:Boolean,
      default:false
    }
  },
  data() {
    return {
      maskShow:false,
      ERR_OK: false,
      loading: false,
      labelMsg: "",
      followLab: "",
      selectGroups: "",
      attention: null,
    };
  },
  created() {},
  methods: {
    async _GetUserGroups(entityId) {
      this.maskShow = true
      let { data, code, msg } = await GetUserGroups({
        entityId: entityId,
      });
      if (code == 1) {
        this.followLab = [...data.groups];
      }
    },
    async cancelRecord(item, index) {
      if (item.loading) return;
      this.maskShow = false
      this.$set(item, "loading", true);
      if (this.type == 1) {
        var { data, code, msg } = await CancelPersonRecord({
          entityId: item.entityId,
        });
      } else if (this.type == 2) {
        var { data, code, msg } = await CancelOrganizationRecord({
          entityId: item.entityId,
        });
      } else if (this.type == 3) {
        var { data, code, msg } = await CancelTwitterRecord({
          entityId: item.entityId,
        });
      }else if (this.type == 4) {
        var { data, code, msg } = await CancelThemeRecord({
          entityId: item.entityId,
          entityType:item.entityType
        });
      }
      item.loading = false;
      if (code == 1) {
        tipSuc("取消关注成功");
        item.attention = 2;
        this.$refs.popover[index].doClose();
      } else {
        tipErr(msg);
      }
    },
    async attentionRecord(item, index) {
      this.loading = true;
      this.maskShow = false
      if (this.type == 1) {
        var { data, code, msg } = await AttentionPersonRecord({
          entityId: item.entityId,
          classifyList: [this.selectGroups],
        });
      } else if (this.type == 2) {
        var { data, code, msg } = await AttentionOrganizationRecord({
          entityId: item.entityId,
          classifyList: [this.selectGroups],
        });
      } else if (this.type == 3) {
        var { data, code, msg } = await AttentionTwitterRecord({
          entityId: item.entityId,
          classifyList: [this.selectGroups],
        });
      }else if (this.type == 4) {
        var { data, code, msg } = await AttentionThemeRecord({
          entityId: item.entityId,
          classifyList: [this.selectGroups],
          entityType:item.entityType
        });
      }

      this.loading = false;
      if (code == 1) {
        tipSuc("关注成功");
        item.attention = 1;
        this.$refs.popover[index].doClose();
      } else {
        tipErr(msg);
      }
    },
    removeRecord(item,index){
      this.$emit("handleRemove", { ...item })
    },
    changeFollow(items) {
      this.selectGroups = items;
    },
    addLab(list) {
      if (!this.labelMsg) {
        return;
      } else {
        list.push(this.labelMsg);
        this.labelMsg = "";
      }
    },
    saveLab(item) {
      console.log(item);
    },
    handleLinkId(item) {
      this.$emit("handleLinkId", { ...item });
    },
  },
};
</script>

<style lang="scss" scoped>
.info-item {
  padding: 30px 30px 24px 30px;
  background: #262930;
  margin-bottom: 10px;
  display: flex;
  border:1px solid #262930;
  cursor:pointer;
  &:hover{
    // background:#32353c
    // background:#cc7029;
    border:1px solid rgba(204, 112, 41, 0.6);
    box-shadow: 0 0 10px 0 rgba(204, 112, 41, 0.8);
  }
  &:active{
    border:1px solid #cc7029;
  }
  .pic {
    width: 90px;
    height: 90px;
    margin-right: 20px;
    &.rad {
      border-radius: 50%;
    }
  }
  .info-box {
    flex: 1;
    .info {
      min-height: 90px;
    }
  }
  .name-time {
    width: 100%;
    justify-content: space-between;
    font-size: 18px;
    line-height: 20px;
    color: #fff;
    font-weight: bold;
    margin-bottom: 14px;
    position: relative;
    
    .btn-box /deep/ {
      position: absolute;
      top: -10px;
      right: 0;
      height: 34px;
      display:flex;
      .follow{
        display: block;
        width: 80px;
        height: 34px;
        text-align: center;
        line-height: 34px;
        box-sizing: border-box;
        border-radius: 2px;
        font-size: 14px;
        color: #cc7029;
        background: rgba(204, 112, 41, 0.1);
        margin-left:20px;
        cursor: pointer;
        .el-icon-plus {
          color: #cc7029;
          font-weight: 700;
          margin-right: 5px;
        }
      }
      
    }
    .no {
      border: .5px solid #cc7029;
      background: transparent;
    }
  }
  .label {
    display: flex;
    overflow: hidden;
    span {
      height: 28px;
      line-height: 28px;
      padding: 0 8px;
      font-size: 12px;
      color: #828999;
      background: #2e323b;
      margin-right: 10px;
    }
    margin-bottom: 12px;
  }
  .info-tit {
    font-size: 14px;
    color: #b8becc;
    line-height: 24px;
  }
  .all {
    display: flex;
    span {
      margin-right: 56px;
      font-size: 14px;
      color: #8a8e99;
    }
  }
}
</style>
<style lang="scss">
.follow-tab {
  font-size: 14px;
  color: #b8becc;
  padding: 8px;
  .tit {
    color: #eeeeee;
    margin-bottom: 18px;
  }
  .tab-item {
    margin-bottom: 18px;
    display: flex;
    align-items: center;
    cursor: pointer;
    .check {
      width: 14px;
      height: 14px;
      border-radius: 2px;
      box-sizing: border-box;
      border: 1px solid #b8becc;
      margin-right: 10px;
    }
    .active {
      border: none;
      background: #cc7029;
      position: relative;
      &:after {
        position: absolute;
        top: 2px;
        left: 1px;
        content: "";
        width: 10px;
        height: 4px;
        border: 2px solid #2d3138;
        border-radius: 1px;
        border-top: none;
        border-right: none;
        background: transparent;
        transform: rotate(-45deg);
      }
    }
    .label-msg {
      width: 100px;
      height: 24px;
      border: 1px solid #414852;
      box-sizing: border-box;
      padding: 0 8px;
      background: transparent;
      color: #fff;
      font-size: 12px;
    }
    .el-icon-plus {
      width: 14px;
      height: 14px;
      margin-right: 10px;
      font-size: 14px;
      color: #cc7029;
    }
    .add {
      font-size: 14px;
      color: #cc7029;
    }
  }
  .saveLab {
    margin-left: 24px;
    background: #cc7029;
    width: 50px;
    height: 26px;
    line-height: 26px;
    background: #cc7029;
    border-radius: 2px;
    font-size: 14px;
    color: #fff;
    padding: 0;
    cursor: pointer;
  }
}
.cont-right{
  position:relative
}
.mask{
  position:absolute;
  width:100%;
  height:100%;
  background:transparent;
  z-index:10;
  
}
</style>
